#include "RingQueue.hpp"
#include "Log.hpp"
#include <unistd.h>
#include <iostream>

void *productor(void *args)
{
    RingQueue<int> *rq = static_cast<RingQueue<int> *>(args);

    int cnt = 1000;
    while (cnt--)
    {
        rq->Push(cnt);
        std::cout << "Productor Push: " << cnt << std::endl;
        sleep(1);

    }
}

void *consumer(void *args)
{
    RingQueue<int> *rq = static_cast<RingQueue<int> *>(args);
    while (true)
    {
        int data;
        rq->Pop(&data);
        std::cout << "Comsur get: " << data << std::endl;
    }
}

int main()
{
    // Log log;
    // log.LogMessage(Warning,"hello %s %d ","Linux",20240317);
    // printf("\n");

    RingQueue<int> *rq = new RingQueue<int>();
    pthread_t c[2], p[3];
    pthread_create(&p[0], nullptr, productor, rq);
    pthread_create(&c[0], nullptr, consumer, rq);

    pthread_create(&p[1], nullptr, productor, rq);
    pthread_create(&c[1], nullptr, consumer, rq);
    pthread_create(&p[2], nullptr, productor, rq);

    pthread_join(p[0], nullptr);
    pthread_join(c[0], nullptr);

    pthread_join(p[1], nullptr);
    pthread_join(c[1], nullptr);
    pthread_join(p[2], nullptr);

    return 0;
}